#include "stm32f10x.h"
#include "RS232.h"
#include "cc2500.h"
#include "timeconfig.h"
#include "led.h"




unsigned long timercount= 0 ;

extern u8  RF_RxBuf[64];

void delay100ms(void)
{
	u32 i,j;
	for(i= 0;i<500;i++)
		for(j=0;j<7200;j++);
}

void SendStr(u8 *p)
{
	while(*p)
	{
		while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); 
		USART_SendData(USART1, *p);
		p++;
	
	}
}



void Sevice(void)
{
	unsigned char tem;

	tem = CheckTypeCMD();
	switch(tem)
	{
		case 100:   if(CheckHubAdd()==OK)
		 			 {
 						if(CheckCRC()!=OK )
						{
							LedOn(LED3)	;
							memsetRxBuf();
						}
						else
						{  
			  				LedOn(LED4);			  
			   				SendToESL();		
		       				memsetRxBuf();
			   				LedOff(LED4);
						}
					}
					break;
		case 101:   break	 ;
		case 102:   break	 ;
		case 103:   break	 ;
		case 104:   break	 ;
		case 105:   break	 ;
		case 106:   break	 ;
		case 107:   break	 ;
		case 108:   break	 ;
		case 109:   break	 ;
		case 110:  LedOn(LED3)	; 
				   SendToESL();
					//SendESLID();	
					break ;
		case 111:   
					SendHubAdressToPC();
					//LedOff(LED3)	;
					break ;
		case 112:	break	 ;
		case 113:   break	 ;
		default :   break;
	}
}


int main(void)
{ 		  
	Uart1_init(9600);
	RF_Init();
    LEDInit();
	LedOff(LED4);
	LedOff(LED3);	
	while(1)
	{ 
	   	if(GetRxbufState()==OK)
		{ 
		
		 	 Sevice();
							
		}
	}
}

